#include<stdio.h>
#include<stdlib.h>
#include "header.h"


extern node *head;
extern node *curr;

//creates a new linked list
node* reverse(){
	node *rev=NULL;
	node *ptr=head;
	while(ptr!=NULL){
		if(rev==NULL){
			rev=create(ptr->val);
		}
		else{
			node *temp=create(ptr->val);
			temp->next=rev;
			rev=temp;
		}
		ptr=ptr->next;
	}
	return rev;
}

//converts the current linked list into a reverse linked list
node* rev1(node *head){
	node *ptr=head;
	node *temp=head;
	ptr=ptr->next;
	temp->next=NULL;
	node *n1;
	while(ptr->next!=NULL){
			n1=ptr->next;
			ptr->next=temp;
			temp=ptr;
			ptr=n1;
	}
	ptr->next=temp;
	return ptr;
}

int main(){
	int i;
	do{
		scanf("%d",&i);
		if(i==-1)break;
		insert(i);
	}while(1);
	display(rev1(head));
	
}
